package org.ftc.dao;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.ftc.domain.CodeResolution;
import org.ftc.form.CodeResolutionForm;
import org.hibernate.Criteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

@Repository
public class CodeResolutionDao extends CurrentDao <CodeResolution, String> {

	@Override
	public CodeResolution load(String id) {
		return super.load(id);
	}

	@Override
	public CodeResolution get(String id) {
		return super.get(id);
	}

	@Override
	public synchronized boolean save(CodeResolution entity) {
		return super.save(entity);
	}

	@Override
	public synchronized boolean saveOrUpdate(CodeResolution entity) {
		return super.saveOrUpdate(entity);
	}

	@Override
	public synchronized boolean update(CodeResolution entity) {
		return super.update(entity);
	}

	@Override
	public synchronized boolean delete(CodeResolution entity) {
		return super.delete(entity);
	}

	@Override
	public synchronized boolean delete(String id) {
		return super.delete(id);
	}
	
	@Override
	public List<CodeResolution> findPage(int offset, int pageSize) {
		return super.findPage(offset, pageSize);
	}

	@Override
	public List<CodeResolution> findAll() {
		return super.findAll();
	}

	@Override
	public long countAll() {
		return super.countAll();
	}

	@SuppressWarnings("unchecked")
	public List<CodeResolution> findPage(CodeResolutionForm form) {
		try {
			Criteria criteria = getSession().createCriteria(CodeResolution.class);
			if (StringUtils.isNotBlank(form.getName())){
				criteria.add(Restrictions.ilike("name", form.getName() , MatchMode.ANYWHERE));
			}
			criteriaSort(form, criteria);
			List<CodeResolution> list = (List<CodeResolution>) criteria.list();
			return list;
		} catch (Exception e) {
			getLog().error(e.toString());
			return null;
		}
	}

}
